/*
 * Copyright 2009 Brian Mackay brianwmackay@msn.com
 *   All Rights Reserved. See end of file
 */
package com.bmackay.vonsteuben.model;


import com.bmackay.vonsteuben.job.control.SequenceProccessing;
import com.bmackay.vonsteuben.job.display.JobThread;
import com.hp.hpl.jena.graph.Factory;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.TripleMatch;
import com.hp.hpl.jena.graph.impl.GraphBase;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.shared.ReificationStyle;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import org.apache.hadoop.mapred.jobcontrol.JobControl;

public class VonSteubenGraph extends GraphBase implements Graph {

    private Graph graph = Factory.createGraphMem(ReificationStyle.Minimal);

    public VonSteubenGraph(Model model) {
        if (verifyModel(model)) {
            sequence(model);
        }
    }

    public VonSteubenGraph(Resource assemblerResource) {
        if (verifyModel(assemblerResource.getModel())) {
            if (verify(assemblerResource) == true) {
                sequence(assemblerResource.getModel());
            }
        }
    }

    private boolean verify(Resource assemblerResource) {
        boolean hasRequired = true;

        return hasRequired;
    }

    private void sequence(Model model) {

        SequenceProccessing sequenceProccessing = new SequenceProccessing();
        setJobThread(sequenceProccessing.sequence(model));
    }

    private void setJobThread(JobControl jobControl) {

        JobThread jobThread = new JobThread();
        jobThread.showProgress(jobControl);
    }

    public Graph getGraph() {
        return this.graph;
    }

    private boolean verifyModel(Model model) {
      //  DebugModel.write(model);
        if (model == null) {
            System.out.println("!!  model is null!!!");
            return false;
        }
        return true;
    }

    @Override
    protected ExtendedIterator graphBaseFind(TripleMatch arg0) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

/*
 * Copyright 2009 Brian Mackay brianwmackay@msn.com
 * All Rights Reserved.
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
